<?php

class MSanPham extends CI_Model
{
	function danhsachsanpham($madm)
	{
		$this->db->where('madm', $madm);
		$this->db->where('hienthi', 'true');		
		return $this->db->get('sanpham')->result();
	}
	
	function danhsachsanphamlimit($madm, $sodong, $dongbatdau)
	{
		$this->db->where('madm', $madm);
		$this->db->where('hienthi', 'true');		
		return $this->db->get('sanpham',$sodong, $dongbatdau)->result();
	}
	
	function danhsachAdmin()
	{
		return $this->db->get('sanpham')->result();
	}
	
	function xoadolan($masp)
	{
		$this->db->where('masp', $masp);
		$this->db->delete('sanpham');
	}
	
	function capnhatdolan($masp, $tensp, $gia, $soluong, $hinh, $mota, $hienthi)
	{
		$this->db->where('masp', $masp);
		$this->db->set('tensp', $tensp);
		$this->db->set('gia', $gia);
		$this->db->set('soluong', $soluong);
		$this->db->set('hinh', $hinh);
		$this->db->set('mota', $mota);
		$this->db->set('hienthi', $hienthi);
		$this->db->update('sanpham');
	}
	
	function thongtindolan($masp)
	{
		$this->db->where('masp', $masp);
		return $this->db->get('sanpham')->row();
	}
	
	function themdolan($tensp, $gia, $soluong, $hinh, $mota, $hienthi, $madm)
	{
		$this->db->set('tensp', $tensp);
		$this->db->set('gia', $gia);
		$this->db->set('soluong', $soluong);
		$this->db->set('hinh', $hinh);
		$this->db->set('mota', $mota);
		$this->db->set('hienthi', $hienthi);
		$this->db->set('madm', $madm);
		$this->db->insert('sanpham');
	}
	
	function danhsachsanphammoinhat()
	{
		$this->db->order_by('masp', 'desc');
		return $this->db->get('sanpham', 8, 0)->result();
	}
	
	function danhsachsanphamcungloai($madm)
	{
		$this->db->where('madm', $madm);
		$this->db->where('hienthi', 'true');
		$this->db->order_by('masp', 'desc');
		return $this->db->get('sanpham', 4, 0)->result();
	}
	
	function searchsp($search)
	{
		$this->db->like('tensp', $search);
		return $this->db->get('sanpham')->result();
	}
	
}

?>